package cn.tedu.charging.cost.controller;

import cn.tedu.chaging.common.pojo.param.ChargingProcessParam;
import cn.tedu.chaging.common.web.JsonResult;
import cn.tedu.chaging.common.pojo.vo.ChargingProcessVO;
import cn.tedu.charging.cost.service.CostService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 计价服务控制器
 */
@Slf4j
@RestController
@RequestMapping("/cost")
@Api(tags = "计价服务")
public class CostController {

    @Autowired
    private CostService costService;

    /**
     * 计算电费 计算总费用和时长
     * 计算电费的入参
     */
    @ApiOperation("计算电费")
    @PostMapping("/calculate")
    public JsonResult calculateCost(@RequestBody ChargingProcessParam chargingProcessParam) {
        ChargingProcessVO chargingProcessVO = costService.calculateCost(chargingProcessParam);
        return JsonResult.ok(chargingProcessVO);
    }
    /**
     * 获取订单花费
     */
    @ApiOperation("订单花费")
    @GetMapping("/info/{orderNo}")
    public JsonResult info(@PathVariable("orderNo") String orderNo) {
        ChargingProcessVO chargingProcessVO = costService.getOrderCost(orderNo);
        return JsonResult.ok(chargingProcessVO);
    }
}
